from typing import List
# 用程序模拟单通道，非对称双通道，对称双通道的使用情况
ins_n = 2000  # 指令条数
cpi = 19  # 每一条指令执行的时钟周期数

time_record = [0, 0, 0]

if __name__ == '__main__':
    # 单通道
    ins_single = ins_n
    counter = 0
    while ins_single > 0 or counter > 0:
        if counter == 0:
            ins_single -= 1
            counter += cpi
            pass
        else:
            counter -= 1
            pass
        time_record[0] += 1
        pass
    # 不对称双通道
    ins_unbalance = ins_n
    counter = [0, 0]
    while ins_unbalance > 0 or counter[0] > 0 or counter[1] > 0:
        bank_i = (ins_unbalance % 3) % 2
        if counter[bank_i] <= 0:
            counter[bank_i] = cpi
            ins_unbalance -= 1
            pass
        else:
            counter[0] -= 1
            counter[1] -= 1
            pass
        time_record[1] += 1
        pass
    # 对称双通道
    ins_double = ins_n
    counter = [0, 0]
    while ins_double > 0 or counter[0] > 0 or counter[1] > 0:
        bank_i = ins_double % 2
        if counter[bank_i] <= 0:
            counter[bank_i] = cpi
            ins_double -= 1
            pass
        else:
            counter[0] -= 1
            counter[1] -= 1
            pass
        time_record[2] += 1
        pass
    print(time_record)  # [40000, 27327, 21000]
    print([v / min(time_record) for v in time_record])  # [1.9047619047619047, 1.3012857142857144, 1.0]
    pass


# 判断一下 tuple 是什么东西？
if __name__ == '__main__':
    print(type((1, 3, 4)))  # <class 'tuple'>
    print(isinstance((1, 2, 3), tuple))  # True
    pass


# 测试一下 join 方法能否链接数字
if __name__ == '__main__':
    # print("-".join([1, 2, 3, 4, "hh"]))  # 此时会报错
    pass


# 测试一下 set 的特性
if __name__ == '__main__':
    a_set = set()
    a_set.add("-".join(["a", "b", "c", "d"]))
    a_set.add("-".join(["a", "b", "c", "d"]))
    a_set.add("-".join(["a", "b", "c", "d"]))
    print(a_set)  # {'a-b-c-d'}
    pass
